/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FilePartsTransferTest;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Victor
 */
public class Client{
    
    private static int LISTENING_PORT = 40100;

    public Client() throws IOException {
        long start = System.currentTimeMillis();
        Socket sock = new Socket("192.168.0.11", LISTENING_PORT);
        byte[] mybytearray = new byte[1024*1024];
        InputStream is = sock.getInputStream();
        
        FileOutputStream fos = new FileOutputStream("../output.png");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        
        int bytesRead = is.read(mybytearray,0,mybytearray.length);
        int current = bytesRead;
        
        do {
            bytesRead = is.read(mybytearray, current, (mybytearray.length-current));
            if(bytesRead >= 0) current += bytesRead;
        } while(bytesRead > -1);
        
        bos.write(mybytearray, 0 , current);
        bos.flush();
        long end = System.currentTimeMillis();
        System.out.println(end-start);
        bos.close();
    }
}
